package org.mirrentools.remoteattendance.admin;

import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 定时计数器
 * @author <a href="https://mirrentools.org">Mirren</a>
 */
public class CounterSchedule extends ScheduledService<Long> {
  private AtomicLong count=new AtomicLong();
  /**
   * 获取当前的计数
   * @return
   */
  public long getCount() {
    return count.get();
  }

  /**
   * 设置当前计数
   * @param count
   */
  public void setCount(long count) {
    this.count.set(count);
  }

  @Override
  protected Task<Long> createTask() {
    return new Task<>() {
      @Override
      protected Long call() throws Exception {
        return  count.getAndIncrement();
      }
    };
  }
}
